<template>
  <view class="page container">
    <z-paging :refresher-enabled="false" :auto-full-height="false" :default-page-size="15" ref="pagingRef"
      v-model="dataList" @query="queryList">
      <view slot="top">
        <u-tabs keyName="title" :list="tabsList" @click="tabClick" lineColor="#C5261D"
          :activeStyle="{ fontWeight: 500, color: '#000' }"></u-tabs>
      </view>
      <view class="h-28 bgc-f7f8fa"></view>
      <view class="goods-list pl-32 pr-32 mt-32">
        <view class="goods-item pb-32" v-for="(item, index) in dataList" :key="index">
          <news-card :info="item"> </news-card>
        </view>
      </view>
    </z-paging>
  </view>
</template>
<script>
import NewsCard from "@/components/rowCards/NewsCard";
import { newsSonCateApi, newsListApi } from "@/services/home.js";
export default {
  data() {
    return {
      currentTab: 0,
      tabsList: [
        {
          name: "全部",
        },
        {
          name: "分类1",
        },
        {
          name: "分类2",
        },
        {
          name: "分类3",
        },
      ],
      btnStyle: {
        backgroundColor: "transparent",
        width: "124rpx",
        height: "56rpx",
        color: "#C5261D",
        borderRadius: "8rpx",
        fontSize: "24rpx",
        padding: 0,
      },
      params: {
        cate_pid: "",
        cate_id: "",
      },
      dataList: [],
    };
  },
  onLoad(options) {
    this.params.cate_pid = options.id;
    this.getNewsSonCate();
  },
  components: {
    NewsCard,
  },
  methods: {
    getNewsSonCate() {
      newsSonCateApi({
        id: this.params.cate_pid,
      }).then((res) => {
        this.tabsList = res.data?.cate_list || [];
      });
    },
    tabClick({ index }) {
      this.currentTab = index;
      this.$refs.pagingRef?.reload();
    },
    queryList(page, page_size) {
      const requestObj = {
        page,
        page_size,
        ...this.params,
      };
      newsListApi(requestObj).then((res) => {
        this.$refs.pagingRef?.complete(res.data?.data || []);
      });
    },
    handleCancelCollect(item) {
      uni.showModal({
        title: "提示",
        content: "确定取消收藏吗？",
        success: (res) => {
          if (res.confirm) {
          }
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.page {}
</style>
